package com.xu.sys.service.impl;

import com.xu.sys.bean.SysRole;
import com.xu.sys.bean.SysRoleMenu;
import com.xu.sys.bean.SysUser;
import com.xu.sys.dao.IRoleDao;
import com.xu.sys.dao.impl.RoleDaoImpl;
import com.xu.sys.service.IRoleService;
import com.xu.sys.service.IUserService;
import com.xu.sys.utils.PageUtils;

import java.util.List;

public class RoleServiceimpl implements IRoleService {
    private IRoleDao dao = new RoleDaoImpl();
    private IUserService UserService = new IUserServiceimpl();
    @Override
    public List<SysRole> list(SysRole entity) {
        return dao.list(entity);
    }

    @Override
    public int save(SysRole entity) {
        return dao.save(entity);
    }

    @Override
    public SysRole findById(int id) {
        return dao.findById(id);
    }

    @Override
    public int updteById(SysRole entiry) {
        return dao.updteById(entiry);
    }

    @Override
    public int deleteById(int id) {
        return dao.deleteById(id);
    }

    @Override
    public void listPage(PageUtils pageUtils) {
        //查询分页的数据
        List<SysRole> list = dao.listPage(pageUtils);
        int count = dao.count(pageUtils);
        // 封装分页的数据
        pageUtils.setList(list);
        pageUtils.setTotalCount(count);
    }

    @Override
    public int count(PageUtils pageUtils) {
        return dao.count(pageUtils);
    }

    @Override
    public boolean checkRoleDispatch(int roleId) {
        SysUser entity = new SysUser();
        entity.setRoleId(roleId);
        return UserService.list(entity).size()== 0 ? true : false;
    }

    @Override
    public void deleteMenuByRoleId(int id) {
        dao.deleteMenuByRoleId(id);
    }

    @Override
    public void saveDispatcherMenu(int roleId, String menuId) {
        dao.saveDispatcherMenu(roleId,menuId);
    }

    @Override
    public List<SysRoleMenu> queryByRoleId(int roleId) {
        return dao.queryByRoleId(roleId);
    }


}
